package cn.edu.gxu.xingjian.teacherassistant.web;

import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.gxu.xingjian.teacherassistant.domain.Curriculum;
import cn.edu.gxu.xingjian.teacherassistant.domain.Useres;
import cn.edu.gxu.xingjian.teacherassistant.domain.UseresCurr;
import cn.edu.gxu.xingjian.teacherassistant.util.Session;

@RequestMapping("/userescurrs")
@Controller
@RooWebScaffold(path = "userescurrs", formBackingObject = UseresCurr.class)
public class UseresCurrController {
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
	public String delete(@PathVariable("id") Long id,
			@RequestParam(value = "page", required = false) Integer page,
			@RequestParam(value = "size", required = false) Integer size,
			Model uiModel) {
		Useres u = Useres.findUseres(Session.getInstance().getUid());
		Curriculum c = Curriculum.findCurriculum(id);
		UseresCurr uc = UseresCurr.findUseresCurrsByUidAndCid(u, c).getSingleResult();
		uc.remove();
		uiModel.asMap().clear();
		uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
		uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
		return "redirect:/curriculums";
	}
}
